extends CharacterBody2D

@export var player_dm:PlayerDM 
@export var effective_db:EffectiveDB :
	set(value):
		effective_db = value
# Called when the node enters the scene tree for the first time.
func _ready():
	# 打印对象 可以和player中的打印对比 如果不特别的进行唯一化，那么他们的编号应该是一致的
	print("UIEVENT = ",player_dm.UI_EVENT)
	print("EffectiveDB = ", effective_db)
	#要等改链接的信号都完成链接 然后才能调用更新HP的操作 因此要 call_deferred
	$TestEffective.character = player_dm
	#print("$TestEffective.character", $TestEffective.character, "  player_dm = ", player_dm)
	call_deferred("test")
	pass # Replace with function body.

# player_dm.hp_max = 1000 的操作会触发setter操作，用UI事件总线发出信号
func test():
	print("-------------init hp-------------")
	player_dm.hp_max = 1000
	player_dm.hp = 100
	print("hp = ", player_dm.hp, " max = ", player_dm.hp_max)
	print("-------------item db version-------------")
	print("物品数据版本: ",player_dm.inventory.item_db.get_version())
	# 演示一个效果
	#$TestEffective.apply()
	print("所有效果ID:", effective_db.get_all_effective_id())
	
	

func get_input():
	var input_direction = Input.get_vector("left", "right", "up", "down")
	velocity = input_direction * player_dm.speed
	
	if Input.is_action_just_pressed("jia_hp"):
		player_dm.hp += 100
		if(player_dm.hp > player_dm.hp_max) :
			player_dm.hp = player_dm.hp_max
	
	if Input.is_action_just_pressed("kou_hp"):
		player_dm.hp -= 100
		if(player_dm.hp < 0) :
			player_dm.hp = 0
		

func _physics_process(_delta):
	get_input()
	move_and_slide()
	
